<?php
namespace common\records;
use Yii;
use yii\db\ActiveRecord;

class ChargeRule extends ActiveRecord
{
    public $imageFile;
    /**
    ** @return string 返回该AR类关联的数据表名
    **/
    public static function tableName()
    {
        return 'charge_rule';
    }

    public function rules()
    {
        return [
            [['money', 'coin'], 'required'],
            [['money', 'coin'], 'integer'],
            [['timestamp','photo'], 'string'],
            [['imageFile'], 'file','extensions' => 'png, jpg'],
            ];
    }

    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'money' => '现金金额',
            'coin' => '兑换娃娃币',
            'photo' => '图片',
            'imageFile' => '图片',
            'timestamp' => '规则创建时间',
            ];
    }
    public function beforeSave($insert)
    {
        if (parent::beforeSave($insert)) {
            if ($insert == true) {
                $this->timestamp = date('Y-m-d H:i:s');
            }
            return true;
        }
        return false;
    }
}
